// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import './ui/ui-init.js'
import './util/tool'
import App from './App'
import router from './router'
import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.use(VueAwesomeSwiper)
import { Loadmore } from 'mint-ui';
Vue.component(Loadmore.name, Loadmore);
window.isLoad=false;

Vue.config.productionTip = false

Vue.prototype.$pages={};

/* eslint-disable no-new */
let vm = new Vue({
	el: '#app',
	router,
	template: '<App/>',
	components: { App },
	data(){
		return {
			isLoad: {
				flag: false
			}
		}
	},
	methods:{
		// 把显示or隐藏加载框/吐司框的方法暴露到window对象上,而不把Vue的实例暴露出去
		bindUI: function(){
			let ui={
				showLoading: this.showLoading.bind(this),
				hideLoading: this.hideLoading.bind(this),
				showToast: this.showToast.bind(this),
				hideToast: this.hideToast.bind(this),
				showAlert: this.showAlert.bind(this),
				hideAlert: this.hideAlert.bind(this),
				showQrcode: this.showQrcode.bind(this),
				hideQrcode: this.hideQrcode.bind(this)
			}
			window.ui=ui;
		},
		// 调用登录接口,获取用户id和token
		login: function(){
			let json={};
			let openId=window.localStorage.getItem('openid');
			if(openId){
				json.openId=openId;
			} else {
				this.showQrcode();
				// json.openId='x';
				// json.openId='oy7fvwDXfvX6bvdC_wu1qDKstNkc';
			}
			this.$util.ajax('/customer/login','POST',json).then(function(res){
				if(res.code=='100000'){
					window.localStorage.setItem('customerId',res.data.customerId);
					window.localStorage.setItem('AISessionToken',res.data.token);
				}
			});
		}
	},
	mounted: function(){
		window.vm_=this;
		this.bindUI();
		this.login();
		window.isLoad=this.isLoad;
		this.$util.shareDeny();
	}
})
